﻿using NewsMine.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using NewsMine.DomainObjects;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace NewsMine.Utilities.Tests
{
    
    
    /// <summary>
    ///This is a test class for ObjectByteArrayConverterTest and is intended
    ///to contain all ObjectByteArrayConverterTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ObjectByteArrayConverterTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

      


    
        [TestMethod()]
        public void ObjectToByteArrayProtoBuffTestHelper()
        {
            FeedItem obj = new FeedItem { Title = "Hi.. Surendra", PubDate = DateTime.Now, Rank = 10, Body = "saljfalfjaljfa faldlkadjsflajd f" }; 

            string testFeedItemPath = "C:\\testFeedItem.feed";

            BinaryFormatter formatter = new BinaryFormatter();
            var stream = File.Open(testFeedItemPath, FileMode.Open);

            try
            {
                obj = (FeedItem) formatter.Deserialize(stream);
                stream.Close();
            }
            catch
            {
                obj = new FeedItem { Title = "Hi.. Surendra", PubDate = DateTime.Now, Rank = 10, Body = "saljfalfjaljfa faldlkadjsflajd f" }; 
            }

            var data = ObjectByteArrayConverter.ObjectToByteArrayProtoBuff<FeedItem>(obj);
            var data2 = ObjectByteArrayConverter.ObjectToByteArray(obj);

            
            FeedItem expectedFeedItem = (FeedItem) ObjectByteArrayConverter.ByteArrayToObjectProtoBuff<FeedItem>(data);
            
        }

     
    }
}
